<%@page import="cn.com.api.entity.ApiType"%>
<%@page import="java.util.List"%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport"
	content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,member-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<!--[if lt IE 9]>
<script type="text/javascript" src="lib/html5.js"></script>
<script type="text/javascript" src="lib/respond.min.js"></script>
<script type="text/javascript" src="lib/PIE_IE678.js"></script>
<![endif]-->
<link href="css/H-ui.min.css" rel="stylesheet" type="text/css" />
<link href="css/H-ui.admin.css" rel="stylesheet" type="text/css" />
<link href="css/pagination.css" rel="stylesheet" type="text/css" />
<link href="lib/Hui-iconfont/1.0.1/iconfont.css" rel="stylesheet"
	type="text/css" />
<!--[if IE 6]>
<script type="text/javascript" src="http://lib.h-ui.net/DD_belatedPNG_0.0.8a-min.js" ></script>
<script>DD_belatedPNG.fix('*');</script>
<![endif]-->
<title>商品管理</title>
</head>
<body>

	<div class="pd-5">
	<div class="cl bg-1 bk-gray"> 
		<form action="<%=path%>/backstage/batchInsertTopicLink" method="get" class="form form-horizontal" id="form-goods-add" onsubmit="">
			<div class="text-c"> 
				<div class="mt-5 mb-5 cl">
					<label class="form-label col-2">商品名称：</label>
					<div class="formControls col-4">
					<input type="text" name="name" value="${conditions.name}" id="name" placeholder="商品名称" class="input-text col-2">
					<input type="hidden" name="cityid" id="cityid">
					<!--<input type="hidden" name="act_type_id" id="act_type_id" value="${act_type_id}">-->
					</div>
					<div style="margin-left:15px;" class="formControls col-2">
					<button name="" id="" class="btn btn-success f-r radius mr-20" type="submit"><i class="Hui-iconfont">&#xe665;</i> 查询</button>
					</div>
				</div>
				<div style="margin-left:15px;" class="formControls col-2">
					<button name="" id="add" class="btn btn-success f-r radius mr-20" type=""><i class="Hui-iconfont">&#xe665;</i>添加</button>
					</div>
			</div>
		</form>
		</div>


		<div class="mt-20">
			<table
				class="table table-border table-bordered table-hover table-bg table-sort">
				<thead>
					<tr class="text-c">
					    <th><input type="hidden" id="topicId" value="${topicId }"/></th>
						<th width="40">ID</th>
						<th>名称</th>
						<th>价格</th>
						<th>库存</th>
						<th>缩略图</th>
					</tr>
				</thead>
				<tbody>
						<c:forEach items="${goods_list}" var="goods">		
						<tr class="text-c">
							<td><input type="checkbox" value="${goods.goods_id}"
							name="goodsId">
							</td>
							<td>${goods.goods_id}</td>
							<td>${goods.name}</td>
							<td>${goods.price}</td>
							<td>${goods.store}</td>
							<td><img src="${goods.image}" height="30" border="0" /></td>
						</tr>
					</c:forEach>
				</tbody>
			</table>
			<div id="Pagination" class="page-con"></div>
		</div>
	</div>
	<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="lib/layer/1.9.3/layer.js"></script>
	<script type="text/javascript" src="lib/laypage/1.2/laypage.js"></script>
	<script type="text/javascript" src="lib/My97DatePicker/WdatePicker.js"></script>
	<script type="text/javascript"
		src="lib/datatables/1.10.0/jquery.dataTables.min.js"></script>
	<script type="text/javascript" src="js/jquery.pagination.js"></script>
	<script type="text/javascript" src="js/H-ui.js"></script>
	<script type="text/javascript" src="js/H-ui.admin.js"></script>
	<%-- <script type="text/javascript">
		$(function() {
			$("#cityid").val(parent.$("#cityid").val());
			$("#act_type_id").val(parent.$("#actid").val());
			initPager();
		});
		
		var showCount = ${pageInfo.showCount};
		var currentPage = ${pageInfo.currentPage-1};
		var totalResult = ${pageInfo.totalResult};
		function initPager(){
			$("#Pagination").pagination(totalResult, {
                callback: function(new_page_index, pagination_container){
                	var oldLocation = location.href;
                	var pa = "currentPage=" + (new_page_index+1);
            		var shoC = "showCount=" + showCount;
                	var index = oldLocation.lastIndexOf("?");
                	if (index == -1){
                		location.href = oldLocation + "?" + pa + "&" + shoC;
                	}else if (oldLocation.indexOf("currentPage") == -1){
                		location.href = oldLocation + "&" + pa;
                	}else if (oldLocation.indexOf("showCount") == -1){
                		location.href = oldLocation + "&" + shoC;
                	}else{
                		var temp = oldLocation.replace(/currentPage=\d+/, pa);
						var newLocation = temp.replace(/showCount=\d+/, shoC);
                		location.href = newLocation;
                	}
                	return false;
                },
                items_per_page:showCount, 
                load_first_page:false,
                prev_text:'上一页',
                next_text:'下一页',
                ellipse_text:'...',
                num_edge_entries:1,
                num_display_entries:5,
                current_page:currentPage
            });
		}
		
		/*添加*/
		function goods_add(title,url){
			var index = layer.open({
				type: 2,
				title: title,
				content: url
			});
			layer.full(index);
		}
		/*编辑*/
		function goods_edit(obj,id,w,h){
			isZiYing = $("#isZiYing").val();
			var edit_page = "<%=path%>/backstage/goods-add-pre?isZiYing="+isZiYing+"&id="+id;
			var index = layer.open({
				type: 2,
				title: "编辑商品",
				content: edit_page
			});
			layer.full(index);
			//layer_show("编辑商品",edit_page,w,h);
		}
		/*查看*/
		function goods_show(title,url,id){
			var index = layer.open({
				type: 2,
				title: title,
				content: url
			});
			layer.full(index);
		}
		/*删除*/
		function goods_disable(obj,id){
			layer.confirm('确认删除？', {
				btn: ['确认','取消'], 
				shade: false
			},
			function(){
				$.ajax({
					type : "POST",
					url : "<%=path%>/backstage/goods-disable",
					data : "id=" + id,
					error : function() {
						layer.msg('操作失败', {icon:5,time:1000});
					},
					success : function(msg) {
						layer.msg('已删除 ' + msg.information, {icon:6,time:1000});
						$(obj).parents("body").find(".btn-refresh").click();
					}
				});
			},
			function(){
				layer.msg('未删除', {icon:5,time:1000});
			});	
		}
		/*审核*/
		function product_shenhe(obj,id){
			layer.confirm('审核文章？', {
				btn: ['通过','不通过'], 
				shade: false
			},
			function(){
				$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_start(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已发布</span>');
				$(obj).remove();
				layer.msg('已发布', {icon:6,time:1000});
			},
			function(){
				$(obj).parents("tr").find(".td-manage").prepend('<a class="c-primary" onClick="product_shenqing(this,id)" href="javascript:;" title="申请上线">申请上线</a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-danger radius">未通过</span>');
				$(obj).remove();
				layer.msg('未通过', {icon:5,time:1000});
			});	
		}
		/*下架*/
		function product_stop(obj,id){
			layer.confirm('确认要下架吗？',function(index){
				$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" onClick="product_start(this,id)" href="javascript:;" title="发布"><i class="Hui-iconfont">&#xe603;</i></a>');
				$(obj).parents("tr").find(".td-status").html('<span class="label label-defaunt radius">已下架</span>');
				$(obj).remove();
				layer.msg('已下架!',{icon: 5,time:1000});
			});
		}

var type1;
var type2;
var type3;		
function firstChange(theSelect){
			var typeId = theSelect.value;

			if (!type2){
				$.ajax({
					type:"post",
					async:false,
					url:"<%=path%>/backstage/get-types",
					data : {level:2,isZiYing:true},
					success : function(msg){
						type2 = msg;
					}
					});
				}
			var options = "<option value='-1'>--中类--</option>";
			for (var i = 0; i < type2.length; i++){
				if (typeId == type2[i].cBelong){
					var aOption = "<option value='"+type2[i].cCode+"' >"+type2[i].cName+"</option>"
					options += aOption; 
				}
			}
			$("#type2").html(options);
		}
function secondChange(theSelect){
	var typeId = theSelect.value;

	if (!type3){
		$.ajax({
			type:"post",
			async:false,
			url:"<%=path%>/backstage/get-types",
			data : {level:3,isZiYing:true},
			success : function(msg){
				type3 = msg;
			}
			});
		}
	var options = "<option value='-1'>--小类--</option>";
	for (var i = 0; i < type3.length; i++){
		if (typeId == type3[i].cBelong){
			var aOption = "<option value='"+type3[i].cCode+"' >"+type3[i].cName+"</option>"
			options += aOption; 
		}
	}
	$("#type3").html(options);
}	

function beforSubmit(){
	var type1 = $("#type1").val();
	var type2 = $("#type2").val();
	var type3 = $("#type3").val();
	
	var endType = -1;
	if (type3 != -1){
		endType = type3;
	}else if (type2 != -1){
		endType = type2;
	}else if (type1 != -1){
		endType = type1;
	}
	$("#endType").val(endType);
	return true;
}
function searGoods(id,store,price,goodsid,gname,image){
	var index = parent.layer.getFrameIndex(window.name);
	var num=parent.$("#size").val();
	parent.$('#'+num+'_productId').val(id); 
	parent.$('#'+num+'_store').val(store); 
	parent.$('#'+num+'_price').val(price); 
	parent.$('#'+num+'_goodsId').val(goodsid); 
	parent.$('#'+num+'_goods_name').val(gname);
	parent.$('#'+num+'gname').text(gname);  
	parent.$('#'+num+'_gname').val(gname); 
	parent.$('#'+num+'_img').val(image); 
	parent.$('#simg'+num).attr('src','<%=imagePath%>'+image); 
	parent.$("#productid").val(id);
	parent.$("#goodsid").val(goodsid);
	parent.$('#'+num+'_points').val(parseInt(price*100)); 
	parent.layer.close(index);
}
	</script> --%>
	<script type="text/javascript">
	$("#add").click(function(){
	var goodsId = $("input[name='goodsId']:checked");
		if (goodsId.length <= 0){
			var msg = '请勾选商品';
			layer.tips(msg, '#add');
			return ;
		}
		var data = "";
		for (var i = 0; i < goodsId.length; i++){
			data+=goodsId[i].value+",";
		}
		$.ajax({
			type:"post",
			async:false,
			url:"<%=path%>/backstage/batchInsertTopicLink",
			data : {topicId:$("#topicId").val(),goodsId:data},
			success : function(msg){
				layer.msg(data.information,{icon:6});
			}
		});
	});
	</script>
</body>
</html>